package com.ysq.tankgame.gameImg;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

import javax.swing.JFrame;

import com.ysq.tankgame.tankValue.Recorder;

/*
 * 绘制坦克的类
 */

public class DrawTank extends JFrame {

    Mypanel mypanel = null; // 面板
    public static void main(String[] args) {
        new DrawTank(); // 创建窗口
    }

    public DrawTank(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择游戏模式：1.新游戏 2.恢复游戏");
        String key = scanner.nextLine();
        mypanel = new Mypanel(key); // 创建面板
        this.add(mypanel); // 将面板添加到窗口
        new Thread(mypanel).start();
        this.addKeyListener(mypanel); // 添加键盘监听
        this.setSize(1300, 750); // 设置窗口大小
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置关闭窗口
        this.setVisible(true); // 设置窗口可见

        this.addWindowListener(new WindowAdapter(){
            @Override
            public void windowClosing(WindowEvent e){
                Recorder.save();
                System.exit(0);
            }
        });
    }


}
